package com.ecarx.module_log.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ecarx.module_log.R;

import java.util.ArrayList;
import java.util.List;

public class SpinnerAdapter extends BaseAdapter {

    private List<String> mLogLevelList;

    public SpinnerAdapter() {
        this.mLogLevelList = new ArrayList<>();

    }

    public void notifyData(List<String> logLevelList) {
        this.mLogLevelList = logLevelList;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        if (mLogLevelList == null) {
            return 0;
        }
        return mLogLevelList.size();
    }

    @Override
    public Object getItem(int position) {
        return mLogLevelList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_spinner, parent, false);
        TextView textView = (TextView) view.findViewById(R.id.tv_name);
        String levelName = mLogLevelList.get(position);
        textView.setText(levelName);
        return view;
    }
}
